div class: 'hero-unit', ->
  
  h3 "英语别嚣张"

  div id:'cr-stage', style: 'width:100%;'


  script src: '/js/crafty.min.js'
  coffeescript ->
    $ (e)->
      cr_stage = $ '#cr-stage'
      cw = cr_stage.width()
      ch = cr_stage.height()
      Crafty.init cw
      Crafty.canvas.init()

      
      Crafty.background '#555'
      Crafty.scene "loading", ()->
        #Crafty.load ["/js/crafty.min.js"], ()->
        Crafty.scene("select")

      Crafty.scene "select", ()->
        select = Crafty.e("2D,DOM,Text")
                  .text("Select Your Class")
                  .attr({w:Crafty.viewport.width, h:20, x: 5, y: 10})
                  .css({color:"#FFF", "font-size": "3em"})
        bt_toefl = Crafty.e("2D,DOM,Text,Mouse,Button")
                      .text("Toefl")
                      .attr({w:Crafty.viewport.width, x: 30, y: 40})
                      .css({color:"#FFF", "font-size": "1.4em"})
                      .bind("Click", (e)->
                        console.log e.mouseButton
                        Crafty.scene "main"
                      ).bind("MouseOver", (e)->
                        @css({color:"#000"})
                      ).bind("MouseOut", (e)->
                        @css({color:"#FFF"})
                      ).areaMap([0,0], [50, 0], [50,50], [0, 50])

      Player = Crafty.c "player",
        init: (v)->
          @requires("2D,DOM,Text,Collision,SpriteAnimation")
          @attr({x:Crafty.viewport.width|0, y: Crafty.viewport.height-40})
          @css({color:"#F0F", "font-size": "2em"})

      Vocab = Crafty.c "vocab",
        init: ()->
          @requires("2D,DOM,Text,Collision,SpriteAnimation")
          @attr({x: Math.random()*Crafty.viewport.width | 0, y: -10})
          @css({color:"#FFF", "font-size":"2.em"})
          @bind("kv", (e)->
              console.log e
          ).bind("EnterFrame", ()->
          )
        vocab: (v)->
          @text(v)

      Crafty.scene "main", ()->
        p = Crafty.e("player")
              .text("Soddy")
        
      
      Crafty.scene "loading"

